/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUILayer;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import java.util.ArrayList;


/**
 *
 * @author Gruppe 4
 */
public class Utility {
    
    
    private Document doc;
    private ArrayList<AddedProducts> products; 
    private static String FILE = "C:/Users/vildmand/Documents/Pdf.pdf";
    
    public Utility()
    {
        doc = new Document();
        products = new ArrayList<AddedProducts>();
    }
    
    public void savePdf() throws Exception
    {
    
          PdfWriter.getInstance(doc, new FileOutputStream(FILE));
          doc.open();
          
          Font font = new Font();
          //font.setColor(new Color(0xFF, 0xFF, 0xFF));

        Chunk firstLastName = new Chunk("Jesper" + " " + "Mortensen", font);

        Chunk address = new Chunk("Møllebakken 10", font);
        Chunk zipCodeCity = new Chunk("7900" + " " + "Nykøbing Mors", font);

        Phrase phrase = new Phrase(30); // ArrayList of Chunck objects
        phrase.add(firstLastName);
        phrase.add("\n");
        phrase.add(address);
        phrase.add("\n");
        phrase.add(zipCodeCity);
        phrase.add("\n");
        phrase.add("\n");
        phrase.add("\n");

        Phrase phrase2 = new Phrase(30);
        Phrase phrase3 = new Phrase(30);
        Phrase phrase4 = new Phrase(30);
        
        phrase2.add("Vedr." + " " + address);
        phrase3.add("2011/09/09");
        
        phrase4.add("\n");
        phrase4.add("\n");
        phrase4.add("\n");
        phrase4.add("\n");
        phrase4.add("\n");
        
        Paragraph paragraph = new Paragraph();
        paragraph.add(phrase);
        paragraph.add(phrase2);
        paragraph.setAlignment(Element.ALIGN_LEFT);
        paragraph.setSpacingAfter(10);
        //paragraph.setIndentationRight(20);
        Paragraph paragraph2 = new Paragraph();
        paragraph2.add(phrase3);
        paragraph2.setAlignment(Element.ALIGN_RIGHT);
        
        List list = new List(List.UNORDERED, 10);
        
        for(int i = 0; i<getProducts().size(); i++)
        {
            list.add(products.get(i).getAmount() + " " + products.get(i).getName());   
        }
     
        doc.add(paragraph);
        doc.add(paragraph2);
        doc.add(list);
          
        doc.close();
    }

    /**
     * @return the products
     */
    public ArrayList<AddedProducts> getProducts() {
        return products;
    }

    /**
     * @param products the products to set
     */
    public void setProducts(ArrayList<AddedProducts> products) {
        this.products = products;
    }

    
}
